#ifndef _TIMER_H_
#define _TIMER_H_

#define CAP31_PIN         (GPIOA->IDR & GPIO_Pin_6)
#define CAP31_POL_RISING  (TIM3->CCER &= ~TIM_CCER_CC1P) 
#define CAP31_POL_FALLING (TIM3->CCER |= TIM_CCER_CC1P)  

#define CAP32_PIN         (GPIOA->IDR & GPIO_Pin_7)
#define CAP32_POL_RISING  (TIM3->CCER &= ~TIM_CCER_CC2P) 
#define CAP32_POL_FALLING (TIM3->CCER |= TIM_CCER_CC2P)  

#define CAP33_PIN         (GPIOB->IDR & GPIO_Pin_0)
#define CAP33_POL_RISING  (TIM3->CCER &= ~TIM_CCER_CC3P) 
#define CAP33_POL_FALLING (TIM3->CCER |= TIM_CCER_CC3P)  

#define CAP34_PIN         (GPIOB->IDR & GPIO_Pin_1)
#define CAP34_POL_RISING  (TIM3->CCER &= ~TIM_CCER_CC4P) 
#define CAP34_POL_FALLING (TIM3->CCER |= TIM_CCER_CC4P)  


#define CAP41_PIN         (GPIOB->IDR & GPIO_Pin_6)
#define CAP41_POL_RISING  (TIM4->CCER &= ~TIM_CCER_CC1P) 
#define CAP41_POL_FALLING (TIM4->CCER |= TIM_CCER_CC1P)  

#define CAP42_PIN         (GPIOB->IDR & GPIO_Pin_7)
#define CAP42_POL_RISING  (TIM4->CCER &= ~TIM_CCER_CC2P) 
#define CAP42_POL_FALLING (TIM4->CCER |= TIM_CCER_CC2P)  

#define CAP43_PIN         (GPIOB->IDR & GPIO_Pin_8)
#define CAP43_POL_RISING  (TIM4->CCER &= ~TIM_CCER_CC3P) 
#define CAP43_POL_FALLING (TIM4->CCER |= TIM_CCER_CC3P)  

#define CAP44_PIN         (GPIOB->IDR & GPIO_Pin_9)
#define CAP44_POL_RISING  (TIM4->CCER &= ~TIM_CCER_CC4P) 
#define CAP44_POL_FALLING (TIM4->CCER |= TIM_CCER_CC4P)  

#define TIMER_STICK_REFLASH_ADD_VALUE	50
#define TIMER_STICK_REFLASH_MAX_VALUE	1000

#define ICP_MAX_VALUE 2300
#define ICP_MIN_VALUE 700
#define DEFAULT_PWM_VALUE	1000
#define PWM_OUT_FOR_MULTICOPTER_PERIOD  (DELTA_TICK*1000)	// 2000, 2500, ms * 1000

#define DEFAULT_STICK_WITDH				1520
#define DEFAULT_STICK_WITDH_AIL			1520
#define DEFAULT_STICK_WITDH_ELE			1520
#define DEFAULT_STICK_WITDH_THR			1120
#define DEFAULT_STICK_WITDH_RUD			1520

#define MODE_CHANGE_MAX_VALUE	1800
#define MODE_CHANGE_MIN_VALUE	1200

enum RX_ASSIGN
{
	RX_AIL = 0,
	RX_ELE = 1,
	RX_THR = 2,
	RX_RUD,
	RX_AUX1,
	RX_AUX2,	
	RX_AUX3,
	RX_AUX4,
	RX_CH09,
	RX_CH10,
	RX_CH11,
	RX_CH12,
	RX_CH13,
	RX_CH14,
	RX_CH15,
	RX_CH16,
	RX_CH17,
	RX_CH18
};

extern __IO uint16_t ICP_width[8];
extern volatile uint16_t Stick_value[18];
extern volatile uint16_t Stick_value_sbus[18];
extern __IO uint16_t ICP_width_new_flag[8];

extern void stick_low_value(void);
extern void update_stick(void);
extern void Tim_PWM_Init(uint16_t SERVO_PERIOD);
extern void Tim_ICP_Init(void);
extern void Tim_STICK_Init(void);

extern void Tim_ICP_Init_SettingMode(void);
extern void Tim_PWM_Init_SettingMode(void);

extern volatile uint8_t Sbus_enable;

extern volatile uint16_t Ppm_value[9];
#endif
